package com.gljx.web.controller.back.message;

import com.gljx.util.CommonUtil;
import com.gljx.web.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: LiXiang
 * @Description :
 * @Date: Created in 2018-05-02 9:24
 */
@Controller
@RequestMapping(value = "/item")
public class ItemsController {

    /**
     * 进入列表
     * @Author:  LiXiang
     * @Date: Created in 2018-05-02 9:25
     * @return
     */
    @RequestMapping("/page.action")
    public ModelAndView openActivitiImagePage(){
        ModelAndView mav=new ModelAndView();
        mav.setViewName("/backManage/message/item_list");
        return mav;
    }


    /**
     * 查询列表
     * @Author:  LiXiang
     * @Date: Created in 2018-05-02 9:27
     * @param rows           单页条目
     * @param page           页码
     * @param sort           排序字段
     * @param order          排序方式
     * @param ISUSE          是否已办
     * @param messageBegin  开始时间
     * @param messageEnd    结束时间
     * @param TYPE          类型
     * @return
     */
    @RequestMapping("/list.action")
    @ResponseBody
    public Map<String,Object > list(String rows,
                                    String page,
                                    String sort,
                                    String order ,
                                    String ISUSE,
                                    String messageBegin,
                                    String messageEnd,
                                    String TYPE) {
        //转换 属性为数据库可接收属性
        ISUSE = CommonUtil.isConstant(ISUSE,"0","1");

        TYPE = CommonUtil.isConstant(TYPE,"2","1");

        sort = CommonUtil.isConstant(sort,"type","islook","examBeginTime"
                ,"creatTime","message");
        order = CommonUtil.isConstant(order,"asc","desc");

        Map <String,Object > dataMap = new HashMap<String, Object>();

        if(!CommonUtil.flagStringIsDate("yyyy-MM-dd",messageBegin)){
            messageBegin = "no";
        }
        if(!CommonUtil.flagStringIsDate("yyyy-MM-dd",messageEnd)){
            messageEnd = "no";
        }else{
            try {
                messageEnd = CommonUtil.setTimeByDay("yyyy-MM-dd",messageEnd,1);
            } catch (ParseException e) {
                e.getStackTrace();
                messageEnd = "no";
            }
        }

        return messageService.selectItemPage(rows,page,sort,order,ISUSE,messageBegin,messageEnd,TYPE);
    }

    @RequestMapping("/editItem.action")
    @ResponseBody
    public void update(Integer id){

        messageService.editItem(id);
    }

    @Autowired
    private MessageService messageService;
}
